package com.zry.yard.ui.base

import android.app.Dialog
import android.content.pm.ActivityInfo
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.os.Bundle
import android.view.Window
import com.zry.yard.animation.RecyclerViewUtilKt
import com.zry.yard.config.MyActivityManager
import com.zry.yard.config.MyApplication
import com.zry.yard.retrofit.ApiSupport
import com.zry.yard.utils.ToastUtil


abstract class BaseActivity : PermissionActivity(), ApiSupport {
    var myApplication: MyApplication? = null
    var recyclerViewUtilKt: RecyclerViewUtilKt? = null
    var myActivityManager: MyActivityManager? = null
    var loadingDialog: Dialog? = null
    var viewDataBinding: ViewDataBinding? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
        viewDataBinding = getDataBinding()

        myActivityManager = MyActivityManager.getActivityManager()
        myActivityManager?.addActivity(this)
        myActivityManager?.addPermissionActivity(this)
        myApplication = MyApplication.instance()
        //禁止横竖屏切换
        requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

        loadingDialog = ToastUtil.loadingDialog(this)

        initData()
    }


    private fun getDataBinding(): ViewDataBinding {
        return DataBindingUtil.setContentView(this, getLayoutId())
    }

    protected abstract fun getLayoutId(): Int
    protected abstract fun initData()


    protected fun toast(toastMessage: String) {
        ToastUtil.toast(this, toastMessage)
    }


    override fun onDestroy() {
        super.onDestroy()
        myActivityManager?.removePermissionActivity(this)
        myActivityManager?.finishActivity()
    }
}
